//引入路径模块
const path  = require('path')

//引入html打包模块和公共文件模块，并实例化
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
    //配置入口文件
    entry: path.resolve(__dirname, "../src/index.js"),
    // 配置出口文件
    output: {
        path: path.resolve(__dirname, "../build"),
      filename: "./js/main.js",
      publicPath: "/"

    },
    //配置插件
    plugins: [
      new HtmlWebpackPlugin({
          template: path.resolve(__dirname, "../public/index.html")
      }), 
      new CopyWebpackPlugin({
          patterns: [{
              from: path.resolve(__dirname, "../public"),
              to: "public",
              globOptions: {
                  ignore: ["**/index.html"]
              }
          }],
      })],
      module: {
        rules: [
            {
                test: /\.ejs$/,
                loader: 'ejs-loader',
                options: {
                    variable: 'data', // 可以在模块当中使用data进行数据处理
                }
            }],
    },
    resolve:{
      alias:{
        $v: path.resolve(__dirname, "../src/views")
      },
      //配置默认后缀
      extensions: [".js", ".json", ".ejs"],
    },
    //模式
    mode: "production"
  }